/* 
 * Copyright (c)	Insighten Intelligent Equipment co.,LTD
 * 
 *  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * 
 */
/** 
 * @file udp_lib.h
 * @brief udp socket header file
 * @author taco [tacoee@gmail.com]
 * @version 0.1
 * @date 2010-09-06
 */
#ifndef UDP_SERVER_H_
#define UDP_SERVER_H_

#include "sock_util.h"
#include "rwbuf.h"
#include "types.h"


struct _UdpSocket;
typedef struct _UdpSocket UdpSocket;

struct _UdpSocket {
	int fd;
	int port;
	struct sockaddr_in lckaddr;
	socklen_t lckaddr_len; 
	struct sockaddr_in remaddr;
	socklen_t remaddr_len; 
	SocketAttr *attr;
	int connect;
	int sock_flag;
	RwBuf *buf;
};

UdpSocket *udp_socket_new();
Ret udp_socket_destroy(UdpSocket *thiz);
Ret udp_socket_init(UdpSocket *thiz, char *lckaddr, char *remaddr, int port, SocketAttr *attr);
Ret udp_socket_create_bind(UdpSocket *thiz);
Ret udp_socket_connet(UdpSocket *thiz);
Ret udp_socket_buf_init(UdpSocket *thiz, RwBuf *buf);
Ret udp_socket_set_local_addr(UdpSocket *thiz, char *lckaddr, int port);
Ret udp_socket_set_remote_addr(UdpSocket *thiz, char *remaddr, int port);

int udp_socket_send(UdpSocket *thiz, int size);
int udp_socket_recv(UdpSocket *thiz, int size);
#endif /*UPD_SERVER_H_*/

